<?php

/**
 * This is the model class for table "detail_perjalanan_travel".
 *
 * The followings are the available columns in table 'detail_perjalanan_travel':
 * @property integer $ID_DETAIL_TRAVEL
 * @property integer $ID_KOTA
 * @property integer $KOT_ID_KOTA
 * @property integer $ID_TRAVEL
 * @property string $TGL_BERANGKAT
 * @property string $TGL_PULANG
 * @property string $JAM_BERANGKAT
 * @property string $JAM_PULANG
 * @property integer $HARGA_TIKET
 * @property integer $DURASI_TRAVEL
 * @property string $KELAS_TRAVEL
 *
 * The followings are the available model relations:
 * @property PenyediaTravel $iDTRAVEL
 * @property Kota $kOTIDKOTA
 * @property Kota $iDKOTA
 * @property Transaksi[] $transaksis
 */
class DetailPerjalananTravel extends CActiveRecord
{

	/**
	 * Returns the static model of the specified AR class.
	 * @return DetailPerjalananTravel the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'detail_perjalanan_travel';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ID_KOTA, KOT_ID_KOTA, ID_TRAVEL, HARGA_TIKET, DURASI_TRAVEL', 'numerical', 'integerOnly'=>true),
			array('KELAS_TRAVEL', 'length', 'max'=>15),
			array('TGL_BERANGKAT', 'date','format'=>'yyyy-mm-dd'),
			array('TGL_PULANG', 'date','format'=>'yyyy-mm-dd'),
			array('JAM_BERANGKAT', 'date','format'=>'hh:mm:ss'),
			array('JAM_PULANG', 'date','format'=>'hh:mm:ss'),
			array('ID_KOTA, KOT_ID_KOTA, HARGA_TIKET, DURASI_TRAVEL, KELAS_TRAVEL, TGL_BERANGKAT, TGL_PULANG, JAM_BERANGKAT, JAM_PULANG', 'required'),
			//array('TGL_BERANGKAT, TGL_PULANG, JAM_BERANGKAT, JAM_PULANG', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_DETAIL_TRAVEL, ID_KOTA, KOT_ID_KOTA, ID_TRAVEL, TGL_BERANGKAT, TGL_PULANG, JAM_BERANGKAT, JAM_PULANG, HARGA_TIKET, DURASI_TRAVEL, KELAS_TRAVEL', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'iDTRAVEL' => array(self::BELONGS_TO, 'PenyediaTravel', 'ID_TRAVEL'),
			'kOTIDKOTA' => array(self::BELONGS_TO, 'Kota', 'KOT_ID_KOTA'),
			'iDKOTA' => array(self::BELONGS_TO, 'Kota', 'ID_KOTA'),
			'transaksis' => array(self::HAS_MANY, 'Transaksi', 'ID_DETAIL_TRAVEL'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_DETAIL_TRAVEL' => 'Id Detail Travel',
			//'ID_KOTA' => 'Id Kota',
			'ID_KOTA' => 'Kota Asal',
			'KOT_ID_KOTA' => 'Kota Tujuan',
			'ID_TRAVEL' => 'Id Travel',
			'TGL_BERANGKAT' => 'Tgl Berangkat',
			'TGL_PULANG' => 'Tgl Tiba',
			'JAM_BERANGKAT' => 'Jam Berangkat',
			'JAM_PULANG' => 'Jam Tiba',
			'HARGA_TIKET' => 'Harga Tiket',
			'DURASI_TRAVEL' => 'Durasi Travel',
			'KELAS_TRAVEL' => 'Kelas Travel',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_DETAIL_TRAVEL',$this->ID_DETAIL_TRAVEL);
		$criteria->compare('NAMA_KOTA',$this->iDKOTA->NAMA_KOTA);
		$criteria->compare('KOT_ID_KOTA',$this->KOT_ID_KOTA);
		$criteria->compare('ID_TRAVEL',Yii::app()->user->id);
		$criteria->compare('TGL_BERANGKAT',$this->TGL_BERANGKAT,true);
		$criteria->compare('TGL_PULANG',$this->TGL_PULANG,true);
		$criteria->compare('JAM_BERANGKAT',$this->JAM_BERANGKAT,true);
		$criteria->compare('JAM_PULANG',$this->JAM_PULANG,true);
		$criteria->compare('HARGA_TIKET',$this->HARGA_TIKET);
		$criteria->compare('DURASI_TRAVEL',$this->DURASI_TRAVEL);
		$criteria->compare('KELAS_TRAVEL',$this->KELAS_TRAVEL,true);
		
		//$criteria->ID_KOTA = $model->iDKOTA->NAMA_KOTA; 
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function searchLimit()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_DETAIL_TRAVEL',$this->ID_DETAIL_TRAVEL);
		$criteria->compare('ID_KOTA',$this->ID_KOTA);
		$criteria->compare('KOT_ID_KOTA',$this->KOT_ID_KOTA);
		//$criteria->compare('ID_TRAVEL',Yii::app()->user->id);
		$criteria->compare('TGL_BERANGKAT',$this->TGL_BERANGKAT,true);
		$criteria->compare('TGL_PULANG',$this->TGL_PULANG,true);
		$criteria->compare('JAM_BERANGKAT',$this->JAM_BERANGKAT,true);
		$criteria->compare('JAM_PULANG',$this->JAM_PULANG,true);
		$criteria->compare('HARGA_TIKET',$this->HARGA_TIKET);
		$criteria->compare('DURASI_TRAVEL',$this->DURASI_TRAVEL);
		$criteria->compare('KELAS_TRAVEL',$this->KELAS_TRAVEL,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function getMenuList()
    {
        $connection=Yii::app()->db;
        $sql="SELECT ID_KOTA, NAMA_KOTA FROM kota ORDER BY NAMA_KOTA";
        $menu=$connection->createCommand($sql)->query();
        $menu->bindColumn(1,$option_value);
        $menu->bindColumn(2,$option_name);
      
        while($menu->read()!==false)
        {
            $balik[$option_value]=$option_name;          
        }
        return $balik;
    }
	
}